package com.gx.util;

import java.io.UnsupportedEncodingException;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

import org.apache.commons.codec.binary.Hex;
import org.apache.log4j.Logger;


public class Encryption {
	private static Logger log = Logger.getLogger(Encryption.class);
	private Encryption(){}
	
	//md5加密
	public static  String encodeByMD5(String str){
		
		String newStr = null;
		try {
			MessageDigest messageDigest = MessageDigest.getInstance("MD5");
			byte[] md5Bytes = messageDigest.digest(str.getBytes("utf-8"));
			newStr =  Hex.encodeHexString(md5Bytes);
		}catch (UnsupportedEncodingException | NoSuchAlgorithmException e) {
			log.info(e.getCause(),e);
		}
		
		return newStr;
	}
	

}
